/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view;

import connectivity.QueryManager;
import java.awt.Color;
import java.sql.ResultSet;

import java.text.SimpleDateFormat;

import javax.swing.JOptionPane;
import main.BarApplication;

import java.util.Date;
import java.util.List;

import javax.swing.BorderFactory;
import model.Branch;
import model.DbUtils;

/**
 *
 * @author Home
 */
public class VerkoopOverview extends javax.swing.JPanel {

    /**
     * Creates new form GroupActivityOverview
     */
    //current date en format
    SimpleDateFormat dateForm = new SimpleDateFormat("yyyy-MM-dd");
    Date date = new Date();
    ResultSet rs = null;
    private LoginScreen login;

    public VerkoopOverview(LoginScreen login) {
        initComponents();
        this.login = login;
        tableVerkoopOrders();
        addFunctionItemsTocomboBoXVestigin();


    }
//-----------------------------------------------------------------------------
// Vestiging uit database voor de ComboBox
//-------------------------------------------------------------------------

    private void addFunctionItemsTocomboBoXVestigin() {
        QueryManager queryManager = BarApplication.getQueryManager();
        List<Branch> branch1 = queryManager.getVestigingList();
        for (int i = 0; i < branch1.size(); i++) {
            Branch vestiging = branch1.get(i);
            jComboBox_verkoopVestiging.addItem(vestiging.getEstablishment());

        }
    }

    private void tableVerkoopOrders() {
        QueryManager queryManager = BarApplication.getQueryManager();
        jTable_VerkoopOrders.setModel(DbUtils.resultSetToTableModel(queryManager.VerkoopFilterList(rs)));
        jTable_VerkoopOrders.removeColumn(jTable_VerkoopOrders.getColumnModel().getColumn(0)); // REMOVE FISRT COLUMN 
    }

    //Methode om de Table te vullen met informatie uit de database van table Actiteit
    // Cursus
//Activiteit
    private void Update_table() {
        if (jComboBox_onderverp.getSelectedItem().equals("Product")) {
            String vestiging = jComboBox_verkoopVestiging.getSelectedItem().toString();
            QueryManager queryManager = BarApplication.getQueryManager();
            Branch vestigingId = queryManager.getVestigingID(vestiging);
            int idvestiging = vestigingId.getBranchID();
            Date startdatum = jXDatePicker_verkoopBegindatum.getDate();
            Date einddate = jXDatePicker_einddatum.getDate();
            ResultSet result = queryManager.VerkoopFilterProduct(idvestiging, startdatum, einddate);
            jTable_VerkoopOrders.setModel(DbUtils.resultSetToTableModel(result));

        } else {
            if (jComboBox_onderverp.getSelectedItem().equals("Cursus")) {
                String vestiging = jComboBox_verkoopVestiging.getSelectedItem().toString();
                QueryManager queryManager = BarApplication.getQueryManager();
                Branch vestigingId = queryManager.getVestigingID(vestiging);
                int idvestiging = vestigingId.getBranchID();
                Date startdatum = jXDatePicker_verkoopBegindatum.getDate();
                Date einddate = jXDatePicker_einddatum.getDate();
                ResultSet result = queryManager.VerkoopFilterCursus(idvestiging, startdatum, einddate);
                jTable_VerkoopOrders.setModel(DbUtils.resultSetToTableModel(result));
            } else {
                if (jComboBox_onderverp.getSelectedItem().equals("Activiteit")) {
                    String vestiging = jComboBox_verkoopVestiging.getSelectedItem().toString();
                    QueryManager queryManager = BarApplication.getQueryManager();
                    Branch vestigingId = queryManager.getVestigingID(vestiging);
                    int idvestiging = vestigingId.getBranchID();
                    Date startdatum = jXDatePicker_verkoopBegindatum.getDate();
                    Date einddate = jXDatePicker_einddatum.getDate();
                    ResultSet result = queryManager.VerkoopFilterActivitiet(idvestiging, startdatum, einddate);
                    jTable_VerkoopOrders.setModel(DbUtils.resultSetToTableModel(result));

                } else {
                }
            }
        }
    }

        /**
         * This method is called from within the constructor to initialize the
         * form. WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
         */
        @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel3 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jComboBox_verkoopVestiging = new javax.swing.JComboBox();
        jLabel2 = new javax.swing.JLabel();
        jXDatePicker_verkoopBegindatum = new org.jdesktop.swingx.JXDatePicker();
        jLabel3 = new javax.swing.JLabel();
        jXDatePicker_einddatum = new org.jdesktop.swingx.JXDatePicker();
        jButton1 = new javax.swing.JButton();
        jComboBox_onderverp = new javax.swing.JComboBox();
        jLabel4 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        jLabel7 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTable_VerkoopOrders = new javax.swing.JTable();
        jPanel_menu = new javax.swing.JPanel();
        home = new javax.swing.JLabel();
        leden = new javax.swing.JLabel();
        bar = new javax.swing.JLabel();
        factuur = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();

        setBackground(new java.awt.Color(255, 255, 255));

        jPanel3.setBackground(new java.awt.Color(204, 255, 204));
        jPanel3.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));

        jLabel1.setText("Onderverp");

        jLabel2.setText("Begindatum");

        jLabel3.setText("Einddatum");

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/size32/Actions-search-icon16.png"))); // NOI18N
        jButton1.setText("Search");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jComboBox_onderverp.setModel(new javax.swing.DefaultComboBoxModel(new String[] { " ", "Product", "Cursus", "Activiteit" }));

        jLabel4.setText("Vestiging");

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jComboBox_verkoopVestiging, javax.swing.GroupLayout.PREFERRED_SIZE, 137, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2)
                            .addComponent(jLabel3))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jXDatePicker_verkoopBegindatum, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 138, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jXDatePicker_einddatum, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 136, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(18, 18, 18)
                        .addComponent(jComboBox_onderverp, javax.swing.GroupLayout.PREFERRED_SIZE, 137, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 136, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jComboBox_onderverp, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jComboBox_verkoopVestiging, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addGap(17, 17, 17)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jXDatePicker_verkoopBegindatum, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jXDatePicker_einddatum, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(jButton1)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel1.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));

        jLabel7.setFont(new java.awt.Font("Arial", 0, 36)); // NOI18N
        jLabel7.setForeground(new java.awt.Color(4, 54, 128));
        jLabel7.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/icon-48-article.png"))); // NOI18N
        jLabel7.setText("Verkoop Manager");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addGap(27, 27, 27)
                .addComponent(jLabel7, javax.swing.GroupLayout.DEFAULT_SIZE, 363, Short.MAX_VALUE)
                .addGap(500, 500, 500))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel7)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jTable_VerkoopOrders.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane2.setViewportView(jTable_VerkoopOrders);

        home.setText("Home");
        home.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        home.setFocusCycleRoot(true);
        home.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                homeMouseClicked(evt);
            }
        });

        leden.setText("Leden");
        leden.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        leden.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                ledenMouseClicked(evt);
            }
        });

        bar.setText("Bar");
        bar.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        bar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                barMouseClicked(evt);
            }
        });

        factuur.setText("Factuur");
        factuur.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        factuur.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                factuurMouseClicked(evt);
            }
        });

        jLabel9.setText("Activiteit");
        jLabel9.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel9MouseClicked(evt);
            }
        });

        jLabel10.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/size32/Apps-session-logout-icon.png"))); // NOI18N
        jLabel10.setText("logout");
        jLabel10.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel10MouseClicked(evt);
            }
        });

        javax.swing.GroupLayout jPanel_menuLayout = new javax.swing.GroupLayout(jPanel_menu);
        jPanel_menu.setLayout(jPanel_menuLayout);
        jPanel_menuLayout.setHorizontalGroup(
            jPanel_menuLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel_menuLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(home)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(leden)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel9)
                .addGap(18, 18, 18)
                .addComponent(factuur)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(bar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabel10)
                .addContainerGap())
        );
        jPanel_menuLayout.setVerticalGroup(
            jPanel_menuLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel_menuLayout.createSequentialGroup()
                .addContainerGap(15, Short.MAX_VALUE)
                .addGroup(jPanel_menuLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(home)
                    .addComponent(leden)
                    .addComponent(bar)
                    .addComponent(factuur)
                    .addComponent(jLabel9))
                .addContainerGap())
            .addGroup(jPanel_menuLayout.createSequentialGroup()
                .addComponent(jLabel10)
                .addGap(0, 0, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jPanel_menu, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel_menu, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 351, Short.MAX_VALUE)
                    .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

        //Voerd de Filter uit op vestiging en datum en geeft melding als datum leeg is
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        Update_table();

    }//GEN-LAST:event_jButton1ActionPerformed

    private void homeMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_homeMouseClicked
        // TODO add your handling code here:
        BarApplication.getInstance().showPanel(new Home(login));
    }//GEN-LAST:event_homeMouseClicked

    private void ledenMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_ledenMouseClicked
        BarApplication.getInstance().showPanel(new MemberOverview(login));
    }//GEN-LAST:event_ledenMouseClicked

    private void barMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_barMouseClicked

        if (evt != null) {
            BarApplication.getInstance().showPanel(new shopping_bar(login));
        }
    }//GEN-LAST:event_barMouseClicked

    private void factuurMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_factuurMouseClicked
        if (evt != null) {
            BarApplication.getInstance().showPanel(new FactuurOverview(login));
        }
    }//GEN-LAST:event_factuurMouseClicked

    private void jLabel9MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel9MouseClicked
        // TODO add your handling code here:
        if (evt != null) {

            BarApplication.getInstance().showPanel(new GroupActivityOverview(login));
        }
    }//GEN-LAST:event_jLabel9MouseClicked

    private void jLabel10MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel10MouseClicked
        // TODO add your handling code here:
        BarApplication.getInstance().showPanel(new LoginScreen());
    }//GEN-LAST:event_jLabel10MouseClicked
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel bar;
    private javax.swing.JLabel factuur;
    private javax.swing.JLabel home;
    private javax.swing.JButton jButton1;
    private javax.swing.JComboBox jComboBox_onderverp;
    private javax.swing.JComboBox jComboBox_verkoopVestiging;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel3;
    public javax.swing.JPanel jPanel_menu;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTable jTable_VerkoopOrders;
    private org.jdesktop.swingx.JXDatePicker jXDatePicker_einddatum;
    private org.jdesktop.swingx.JXDatePicker jXDatePicker_verkoopBegindatum;
    private javax.swing.JLabel leden;
    // End of variables declaration//GEN-END:variables
}
